<?php
/**
 *
 *
 *
 */
class Yz_Form_Element_TinyMCE
    extends Yz_Form_Element_Abstract
    implements Yz_Form_Element_Interface
{

    protected $name;
    protected $value = "";
    protected $cssClass = "yz-tinymce";


    public function render(Yz_Template_Interface $template)
    {
        $class = $this->getCSSClass();
        $text = htmlspecialchars($this->value);
        $o = <<<html
            <textarea name="{$this->name}" class="{$class}">{$text}</textarea>\n
html;
        $this->includeJS($template);
        return $o;
    }

    protected function includeJS($template)
    {
        $webRoot = $template->webRoot;
        $js = <<<js
$(function(){
   $('textarea.yz-tinymce').tinymce({
      script_url : '{$webRoot}www/tinymce/jscripts/tiny_mce/tiny_mce.js',
      //mode : "specific_textareas",
      //editor_selector : "yz-tinymce",
      dummy: false
   });
});
js;
        $template->includeJS(
            'tinymce-jquery',
            "./www/tinymce/jscripts/tiny_mce/jquery.tinymce.js",
            null
            ) ;
        $template->includeJS(
            'tinymce-init',
            null,
            $js
            ) ;
        return $this;
    }


}
